<template>
  <el-dialog
    :title="!dataForm.docterId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="医生头像" prop="docterImg">
      <el-input v-model="dataForm.docterImg" placeholder="医生头像"></el-input>
    </el-form-item>
    <el-form-item label="医生年龄" prop="docterNian">
      <el-input v-model="dataForm.docterNian" placeholder="医生年龄"></el-input>
    </el-form-item>
    <el-form-item label="医生手机号" prop="docterTell">
      <el-input v-model="dataForm.docterTell" placeholder="医生手机号"></el-input>
    </el-form-item>
    <el-form-item label="医生邮箱" prop="docterEmall">
      <el-input v-model="dataForm.docterEmall" placeholder="医生邮箱"></el-input>
    </el-form-item>
    <el-form-item label="医师名称" prop="docterName">
      <el-input v-model="dataForm.docterName" placeholder="医师名称"></el-input>
    </el-form-item>
    <el-form-item label="医生密码" prop="docterPwd">
      <el-input v-model="dataForm.docterPwd" placeholder="医生密码"></el-input>
    </el-form-item>
    <el-form-item label="收入总金额" prop="docterPrice">
      <el-input v-model="dataForm.docterPrice" placeholder="收入总金额"></el-input>
    </el-form-item>
    <el-form-item label="医生性别" prop="docterSex">
      <el-input v-model="dataForm.docterSex" placeholder="医生性别"></el-input>
    </el-form-item>
    <el-form-item label="问诊金额" prop="docterInquiryprice">
      <el-input v-model="dataForm.docterInquiryprice" placeholder="问诊金额"></el-input>
    </el-form-item>
    <el-form-item label="医师级别" prop="departmentType">
      <el-input v-model="dataForm.departmentType" placeholder="医师级别"></el-input>
    </el-form-item>
    <el-form-item label="病情标签" prop="illnessLabel">
      <el-input v-model="dataForm.illnessLabel" placeholder="病情标签"></el-input>
    </el-form-item>
    <el-form-item label="科室id" prop="departmentId">
      <el-input v-model="dataForm.departmentId" placeholder="科室id"></el-input>
    </el-form-item>
    <el-form-item label="年限" prop="docterAge">
      <el-input v-model="dataForm.docterAge" placeholder="年限"></el-input>
    </el-form-item>
    <el-form-item label="审核状态
" prop="docterAudit">
      <el-input v-model="dataForm.docterAudit" placeholder="审核状态
"></el-input>
    </el-form-item>
    <el-form-item label="是否开启问诊" prop="docterAuditisInquiry">
      <el-input v-model="dataForm.docterAuditisInquiry" placeholder="是否开启问诊"></el-input>
    </el-form-item>
    <el-form-item label="问诊次数" prop="docterCount">
      <el-input v-model="dataForm.docterCount" placeholder="问诊次数"></el-input>
    </el-form-item>
    <el-form-item label="好评度" prop="docterHappy">
      <el-input v-model="dataForm.docterHappy" placeholder="好评度"></el-input>
    </el-form-item>
    <el-form-item label="预约人数" prop="appointment">
      <el-input v-model="dataForm.appointment" placeholder="预约人数"></el-input>
    </el-form-item>
    <el-form-item label="身份证正面" prop="docterCardid">
      <el-input v-model="dataForm.docterCardid" placeholder="身份证正面"></el-input>
    </el-form-item>
    <el-form-item label="医师资格证书" prop="docterCertification">
      <el-input v-model="dataForm.docterCertification" placeholder="医师资格证书"></el-input>
    </el-form-item>
    <el-form-item label="医师执业证书" prop="docterPractice">
      <el-input v-model="dataForm.docterPractice" placeholder="医师执业证书"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          docterId: 0,
          docterImg: '',
          docterNian: '',
          docterTell: '',
          docterEmall: '',
          docterName: '',
          docterPwd: '',
          docterPrice: '',
          docterSex: '',
          docterInquiryprice: '',
          departmentType: '',
          illnessLabel: '',
          departmentId: '',
          docterAge: '',
          docterAudit: '',
          docterAuditisInquiry: '',
          docterCount: '',
          docterHappy: '',
          appointment: '',
          docterCardid: '',
          docterCertification: '',
          docterPractice: ''
        },
        dataRule: {
          docterImg: [
            { required: true, message: '医生头像不能为空', trigger: 'blur' }
          ],
          docterNian: [
            { required: true, message: '医生年龄不能为空', trigger: 'blur' }
          ],
          docterTell: [
            { required: true, message: '医生手机号不能为空', trigger: 'blur' }
          ],
          docterEmall: [
            { required: true, message: '医生邮箱不能为空', trigger: 'blur' }
          ],
          docterName: [
            { required: true, message: '医师名称不能为空', trigger: 'blur' }
          ],
          docterPwd: [
            { required: true, message: '医生密码不能为空', trigger: 'blur' }
          ],
          docterPrice: [
            { required: true, message: '收入总金额不能为空', trigger: 'blur' }
          ],
          docterSex: [
            { required: true, message: '医生性别不能为空', trigger: 'blur' }
          ],
          docterInquiryprice: [
            { required: true, message: '问诊金额不能为空', trigger: 'blur' }
          ],
          departmentType: [
            { required: true, message: '医师级别不能为空', trigger: 'blur' }
          ],
          illnessLabel: [
            { required: true, message: '病情标签不能为空', trigger: 'blur' }
          ],
          departmentId: [
            { required: true, message: '科室id不能为空', trigger: 'blur' }
          ],
          docterAge: [
            { required: true, message: '年限不能为空', trigger: 'blur' }
          ],
          docterAudit: [
            { required: true, message: '审核状态
不能为空', trigger: 'blur' }
          ],
          docterAuditisInquiry: [
            { required: true, message: '是否开启问诊不能为空', trigger: 'blur' }
          ],
          docterCount: [
            { required: true, message: '问诊次数不能为空', trigger: 'blur' }
          ],
          docterHappy: [
            { required: true, message: '好评度不能为空', trigger: 'blur' }
          ],
          appointment: [
            { required: true, message: '预约人数不能为空', trigger: 'blur' }
          ],
          docterCardid: [
            { required: true, message: '身份证正面不能为空', trigger: 'blur' }
          ],
          docterCertification: [
            { required: true, message: '医师资格证书不能为空', trigger: 'blur' }
          ],
          docterPractice: [
            { required: true, message: '医师执业证书不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.docterId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.docterId) {
            this.$http({
              url: this.$http.adornUrl(`/medical/dockerlevel/info/${this.dataForm.docterId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.docterImg = data.dockerLevel.docterImg
                this.dataForm.docterNian = data.dockerLevel.docterNian
                this.dataForm.docterTell = data.dockerLevel.docterTell
                this.dataForm.docterEmall = data.dockerLevel.docterEmall
                this.dataForm.docterName = data.dockerLevel.docterName
                this.dataForm.docterPwd = data.dockerLevel.docterPwd
                this.dataForm.docterPrice = data.dockerLevel.docterPrice
                this.dataForm.docterSex = data.dockerLevel.docterSex
                this.dataForm.docterInquiryprice = data.dockerLevel.docterInquiryprice
                this.dataForm.departmentType = data.dockerLevel.departmentType
                this.dataForm.illnessLabel = data.dockerLevel.illnessLabel
                this.dataForm.departmentId = data.dockerLevel.departmentId
                this.dataForm.docterAge = data.dockerLevel.docterAge
                this.dataForm.docterAudit = data.dockerLevel.docterAudit
                this.dataForm.docterAuditisInquiry = data.dockerLevel.docterAuditisInquiry
                this.dataForm.docterCount = data.dockerLevel.docterCount
                this.dataForm.docterHappy = data.dockerLevel.docterHappy
                this.dataForm.appointment = data.dockerLevel.appointment
                this.dataForm.docterCardid = data.dockerLevel.docterCardid
                this.dataForm.docterCertification = data.dockerLevel.docterCertification
                this.dataForm.docterPractice = data.dockerLevel.docterPractice
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/medical/dockerlevel/${!this.dataForm.docterId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'docterId': this.dataForm.docterId || undefined,
                'docterImg': this.dataForm.docterImg,
                'docterNian': this.dataForm.docterNian,
                'docterTell': this.dataForm.docterTell,
                'docterEmall': this.dataForm.docterEmall,
                'docterName': this.dataForm.docterName,
                'docterPwd': this.dataForm.docterPwd,
                'docterPrice': this.dataForm.docterPrice,
                'docterSex': this.dataForm.docterSex,
                'docterInquiryprice': this.dataForm.docterInquiryprice,
                'departmentType': this.dataForm.departmentType,
                'illnessLabel': this.dataForm.illnessLabel,
                'departmentId': this.dataForm.departmentId,
                'docterAge': this.dataForm.docterAge,
                'docterAudit': this.dataForm.docterAudit,
                'docterAuditisInquiry': this.dataForm.docterAuditisInquiry,
                'docterCount': this.dataForm.docterCount,
                'docterHappy': this.dataForm.docterHappy,
                'appointment': this.dataForm.appointment,
                'docterCardid': this.dataForm.docterCardid,
                'docterCertification': this.dataForm.docterCertification,
                'docterPractice': this.dataForm.docterPractice
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
